﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

#include "GmepBaseInteraction.h"
#include "CommandBase.h"

namespace gcmp
{
    class IUiDocument;
    class IUiView;
    class IModelView;
    class IDocument;
    class CommandParameters;
}

namespace gap
{
    enum class DocumentStates;
}

namespace gmep
{
    class GMEP_BASE_INTERACTION_EXPORT GmepCommandBase : public gcmp::CommandBase
    {
        CANNOT_COPY_OR_ASSIGN(GmepCommandBase);
    public:
        GmepCommandBase(const std::wstring& commandId, bool hasCommandData = false);

        virtual ~GmepCommandBase();

    private:
        // IsEnabled，IsVisible私有，避免子类调用，造成死循环
        virtual bool IsEnabled() const override final;
        virtual bool IsVisible() const override final;

    protected:
        void RunChildCommand(const std::wstring& cmdName, const gcmp::CommandParameters& cmdParams) const;
        bool GetFamilyNameAndInstanceTypeFromCommandParams(const gcmp::CommandParameters& cmdParams, std::wstring &familyName, std::wstring &instanceType);
        bool CheckSelectedElementIsInEditMode() const;
        bool GetParameterFromCommand(const gcmp::CommandParameters& cmdParams, Int64& familyId, Int64& instanceTypeId, std::wstring& familyName, std::wstring& categoryUid, Int64& elementId);
        virtual bool ShouldClearNotificationMessagesBeforeExecution() const override;
        virtual bool IsEnabledImpl() const;
        virtual bool IsVisibleImpl() const;

        // 命令是否会可能修改文档，只读模式下，修改文档的命令会被禁用
        virtual bool IsNeedModifyDocument() const;

        // 命令是否不依赖于文档
        virtual bool IsDocumentIndependent() const { return false; }

        // 获取文档状态： 单机版或协同版
        bool IsLocked3dView() const;
        gap::DocumentStates GetDocumentState() const;

		// 获取文档是否是协同版
		bool IsCloudDocument() const;


    public:
        gcmp::IUiDocument* GetCurrentUIDoc() const;
        gcmp::IUiView* GetCurrentUIView() const;
        gcmp::IModelView* GetCurrentModelView() const;
        gcmp::IDocument* GetCurrentDocument() const;
    };
}
